package com.itany.utils;

import java.util.UUID;

public class StringUtils {

    public static String rename(String fileName) {
        int lastDot = fileName.lastIndexOf(".");
        String suffix = fileName.substring(lastDot);
        return idGenerate() + suffix;
    }

    public static String idGenerate() {
        return UUID.randomUUID().toString();
    }


    /**
     * 模糊查询中对%_转义
     *
     * @param str
     * @return
     */
    public static String escapeStr(String str) {
        if (str == null || "".equals(str.trim())) {
            return null;
        }
        StringBuffer temp = new StringBuffer();
        for (int i = 0; i < str.length(); i++) {
            if (str.charAt(i) == '%' || str.charAt(i) == '_') {
                temp.append("\\").append(str.charAt(i));
            } else {
                temp.append(str.charAt(i));
            }
        }
        return temp.toString();
    }



}
